CHARTS
Photo by René DeAnda on Unsplash
When eating fruit, remember who planted the tree; when drinking clear water, remember who dug the well…
— Vietnamese Proverb
Vietnam imports a diverse number of organic food and beverage products to meet consumer demand for items that cannot be grown or produced locally, a majority of which are fresh fruits and vegetables and processed products. A recent report of the USDA Foreign Agriculture Service analyzed export trends and foresee Vietnam as a potential growth market for imported organic food and beverage products. Let’s take a closer look at the and use a horizontal grouped bar chart to visualize the results.
List of Products
url_root <- "https://raw.githubusercontent.com/UN-AVT/kamino-source/main/sources/0-shared/data/"
url_file <- "vietnam-organic-market/usda-gats-product-group-organics.csv"
url <- paste0(url_root, url_file)
products <- read.csv(url, header = TRUE, stringsAsFactors = FALSE)
products
Exports to Vietnam
# Load data
df <- read.csv("archetypes/organic-exports/usda-gats-organics-vietnam-data.csv", header = TRUE, stringsAsFactors = FALSE)
df$X2017 <- as.integer(df$X2017)
df$X2019 <- as.integer(df$X2019)
df$X2020 <- as.integer(df$X2020)
df
The year columns become a factored column that we can use for grouping or as a visual variable.
# Convert wide to long
df_long <- melt(df, id.vars=c("Partner", "HS.Code", "Product"))
df_long
# Note: value is in thousands of dollars
# Theme parameters
theme_opts <- theme(
legend.position="top",
legend.title = element_blank(),
text = element_text(size=16), # Set font size for plot text (axes labels, legend labels, plot title, etc.)
axis.title = element_blank(), # Remove x and y axes titles
axis.ticks.y = element_blank(),
axis.ticks.x = element_blank(),
panel.background = element_blank(),
plot.title = element_text(size=18), # Increase font size of plot title text
plot.background = element_blank()
)
# Make the plot
v1 <- ggplot(df_long, aes(x = value, y = Product, fill = variable)) +
geom_bar(stat = "identity", position = position_dodge(0.7), width = 0.8) +
scale_x_continuous() +
theme_minimal() +
theme_opts
girafe(ggobj = v1, width_svg = 16, height_svg = 9,
options = list(opts_sizing(rescale = TRUE, width = 0.8)))
Let’s remove the zero values and see how it effects the chart.
# Remove zero values
df_long <- filter(df_long, value > 0)
df_long
Notice the difference?
# Theme parameters
theme_opts <- theme(
legend.position="top",
legend.title = element_blank(),
text = element_text(size=16), # Set font size for plot text (axes labels, legend labels, plot title, etc.)
axis.title = element_blank(), # Remove x and y axes titles
axis.ticks.y = element_blank(),
axis.ticks.x = element_blank(),
panel.background = element_blank(),
plot.title = element_text(size=18), # Increase font size of plot title text
plot.background = element_blank()
)
# Make the plot
v2 <- ggplot(df_long, aes(x = value, y = Product, fill = variable)) +
geom_bar(stat = "identity", position = position_dodge(0.7), width = 0.8) +
scale_x_continuous() +
theme_minimal() +
theme_opts
girafe(ggobj = v2, width_svg = 16, height_svg = 9,
options = list(opts_sizing(rescale = TRUE, width = 0.8)))
# Make the plot
v3 <- ggplot(df_long, aes(x = value, y = variable, fill = Product)) +
geom_bar(stat = "identity", position = position_dodge(0.7), width = 0.8) +
theme_minimal() +
theme_opts
girafe(ggobj = v3, width_svg = 16, height_svg = 9,
options = list(opts_sizing(rescale = TRUE, width = 0.8)))
Comparison against a stacked bar
# Make the plot
v4 <- ggplot(df_long, aes(x = value, y = variable, fill = Product)) +
geom_bar(stat = "identity", position = "stack", width = 0.5) +
theme_minimal() +
theme_opts
girafe(ggobj = v4, width_svg = 16, height_svg = 9,
options = list(opts_sizing(rescale = TRUE, width = 0.8)))